import { request as http } from '@/api/service'

import IBaseObj from '#/index'

const base = '/dict'
// 获取首页信息
export const getDetailByid = (id: number) => {
  return http({
    url: `${base}/list/content/dictId/${id}`,
    method: 'get',
  })
}

export const getCatalogListById = (id: number) =>
  http({
    url: `${base}/content/list/catalogId/${id}`,
    method: 'get',
  })

export const selectDictByCode = (code: string) =>
  http({
    url: `${base}/content/list/${code}`,
    method: 'get',
  })

const getDictCls = () =>
  http({
    url: `${base}/type`,
    method: 'get',
  })
// 字典目录
const getDictCatalogByPage = (data: IBaseObj) =>
  http({
    url: `${base}/catalog/page`,
    method: 'post',
    data,
  })
const getDictCatalogList = (data: IBaseObj) =>
  http(
    {
      url: `${base}/catalog/list`,
      method: 'post',
      data,
    },
    true
  )
const saveDictCatalog = (data: IBaseObj) =>
  http({
    url: `${base}/save/catalog`,
    method: 'post',
    data,
  })
const getDictCatalogById = (id: string | number) =>
  http({
    url: `${base}/catalog/${id}`,
    method: 'get',
  })
const updateDictCatalog = (data: IBaseObj) =>
  http({
    url: `${base}/update/catalog`,
    method: 'post',
    data,
  })
const delCatalogUrl = `${base}/catalog`
const checkExistCatalogCode = (code: string) =>
  http({
    url: `${base}/catalog/exist/${code}`,
    method: 'get',
  })

// 字典数据
const getDictContentByPage = (data: IBaseObj) =>
  http({
    url: `${base}/content/page`,
    method: 'post',
    data,
  })
const saveDictContent = (data: IBaseObj) =>
  http({
    url: `${base}/content/save`,
    method: 'post',
    data,
  })
const getDictContentById = (id: string | number) =>
  http({
    url: `${base}/content/${id}`,
    method: 'get',
  })
const updateContent = (data: IBaseObj) =>
  http({
    url: `${base}/content/update`,
    method: 'put',
    data,
  })
const delContentUrl = `${base}/content`

// 页面帮助信息
export const getWebHelpInfo = (query: string) =>
  http({
    url: `${base}/web/help/${query}`,
    method: 'get',
  })

// 获取省份接口
export const getProvince = () =>
  http({
    url: `${base}/province`,
    method: 'get',
  })
// 获取城市或者县接口
export const getCity = (code: string | number) =>
  http({
    url: `${base}/province/${code}`,
    method: 'get',
  })

export const codeMaps = {
  priority: 'priority', // 优先级
  pass: 'pass', // 是否通过
  orgCls: 'org_cls',
  status: 'status',
  depType: 'depType',
  queryType: 'query_type', // 质疑分类
}

/**
 * 传入字典字段数组，获取相应的字典数组
 * @param {*} data 字典字段数组
 */
export const dictCodeList = [
  // 'patSource', // 患者来源
  // 'age', // 年龄单位
  // 'sex', // 性别
  // 'idType', // 证件类型
  // 'optionDoctor', // 专家专家组
  // 'pricInterval', // 费用
  // 'adept', // 部位
  // 'modality', // 设备类型
  // 'reportStatus', // 报告状态
  // 'partnerType', // 业务类型
  // 'reason', // 取消订单的原因
  // 'times', // 时间
  // 'triageOrderStatus', // 分诊订单状态
  // 'applyStatus', // 申请状态
  codeMaps.orgCls, // 机构类型
  'project_sort', // 项目类型
  'staging', // 分期
  'project_field', // 治疗领域
  'times', // 时间
  'task', // 阅片状态
  'dcm_status', // 核查状态
  codeMaps.priority,
  codeMaps.pass,
]

// 传入字典字段数组，获取相应的字典数组
// 如果不传数组，默认查询所有的字典
export const getByDictCodeList: any = (data: string[] = dictCodeList) =>
  http(
    {
      url: `/dict/content/list/code`,
      method: 'post',
      data,
    },
    true
  )

// 获取字典map
export const getDictMap = (ids: number[]) =>
  http({
    url: `/dict/map/detail`,
    method: 'post',
    data: { ids },
  })

// 获取检查部位
export const getBodyPart = () =>
  http({
    url: `/dict/list/bodypart`,
    method: 'get',
  })

// 获取检查部位
export const getDicomKeys = () =>
  http({
    url: `/dict/list/dicom/keys`,
    method: 'get',
  })

export default {
  getDictCls,
  getDictCatalogByPage,
  getDictCatalogList,
  getCatalogListById,
  saveDictCatalog,
  getDictCatalogById,
  updateDictCatalog,
  delCatalogUrl,
  selectDictByCode,
  getDictContentByPage,
  saveDictContent,
  getDictContentById,
  updateContent,
  delContentUrl,
  checkExistCatalogCode,

  getDictMap,
  getBodyPart,
  getDicomKeys,
}
